package view;

import model.GpsCoordinate;
import model.Map;

public class MapViewUtil {
    
    public static int calculateXpixels(Map map, GpsCoordinate gpsCoord) {
        
        // Calculate reference longitudes and coordinate longitude
        double leftLongitude = map.getTopLeftRef().getLongitude().getDecimal();
        double rightLongitude = map.getBottomRightRef().getLongitude().getDecimal();
        double coordLongitude = gpsCoord.getLongitude().getDecimal() - leftLongitude;
        
        // Calculate coordinate percentage
        // 50% means the coordinate is at the center of the visible map
        double diff = rightLongitude - leftLongitude;
        double percentage = coordLongitude / diff;
        
        // Apply percentage to pixels
        int xPixels = (int)(map.getMapImage().getWidth() * percentage);
        return xPixels;
    }
    
    public static int calculateYpixels(Map map, GpsCoordinate gpsCoord) {
        
        // Calculate reference latitudes and coordinate latitude
        double topLatitude = map.getTopLeftRef().getLatitude().getDecimal();
        double bottomLatitude = map.getBottomRightRef().getLatitude().getDecimal();
        double coordLatitude = gpsCoord.getLatitude().getDecimal() - topLatitude;
        
        // Calculate coordinate percentage
        // 50% means the coordinate is at the center of the visible map
        double diff = bottomLatitude - topLatitude;
        double percentage = coordLatitude / diff;
        
        // Apply percentage to pixels
        int yPixels = (int)((map.getMapImage().getHeight() * percentage));
        return yPixels;
    }
    
}
